<template>
  <base-page-view class-name="invite-container">
    <view class="header-top"></view>
    <view class="invite-avatar">
      <image :src="inviteInfo.head_img" />
    </view>
    <view class="invite-nickName">{{ inviteInfo.nickname }}</view>
    <view v-if="inviteInfo.PersonalizedSignature" class="signature">{{ inviteInfo.PersonalizedSignature }}</view>
    <view class="invite-title">碧选格言</view>
    <view class="invite-content">
      <view>没有一种生活，能够凌驾于自由之上。</view>
      <view>没有一个随随便便的信仰，能与1,500,000人共鸣</view>
      <view>分享美丽，让自己独立</view>
      <view>你的创业路上始终有我，</view>
      <view>从过去到现在，为更好而战。</view>
      <view>BETTER IS NEWLIFE</view>
    </view>
    <view class="invite-btn" @click="goLogin">现在去登录</view>
  </base-page-view>
</template>
<script>
import { toMpHomePage } from '@/utils/navigateTo'
import './index.scss'
export default {
  data() {
    return {
      topResource: {
        centerCont: ''
      },
      inviteCode: '',
      inviteInfo: {}
    }
  },
  onLoad(options) {
    this.inviteCode = uni.getStorageSync('share_code')
    if (!this.inviteCode) { return }
    this.getInfoByInviteCode()
  },
  methods: {
    async getInfoByInviteCode() {
      const res = await this.$api.mineApi.getInfoByInviteCode(this.inviteCode)
      if (res.success) {
        this.inviteInfo = res.data
        if (!this.inviteInfo.head_img) {
          this.inviteInfo.head_img = '/static/images/mine/touxiang.png'
        }
        this.inviteInfo.nickname = decodeURIComponent(this.inviteInfo.nickname)
        // uni.setStorageSync('__invite_code__', this.inviteCode)
      }
    },
    goLogin() {
      if (this.$store.state.token) {
        const user = this.$store.state.userInfo
        const inviteCode = uni.getStorageSync('share_code')
        if (!(user && !user.referral_code && user.current_member_card_type < 3) || (user && inviteCode === user.invite_code)) {
          toMpHomePage()
          return
        }
      }
      uni.setStorageSync('pageAfterLogin', '/pages/home/index')
      this.$navigateTo('/pages/login/index')
    }
  }
}
</script>
